package com.comac.print.component.app.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 时间类型
 */
public class DateUtil {

    /**
     * 时间类型转换
     * @param date
     * @return
     */
    public static LocalDateTime dateToLocalDate(Date date){
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        return  instant.atZone(zoneId).toLocalDateTime();
    }

    /**
     * LocalDateTime 转string
     * @param dateTime
     * @return
     */
    public static String localDateTimeToString( LocalDateTime dateTime) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return df.format(dateTime);
    }
}
